package com.auxgroup.smarthome;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

/**
 * Created by kevinchen on 2017/9/5.
 * 奥克斯多联机wifi远程监控通讯协议 Version 1.7 协议a表
 */
public enum BusinessDatapointControlEnum {
    /**
     * A
     */
    TEMPERATURE("temperature",5,"A","设定温度",8,39),
    UP_DOWN_SWING("up_down_swing",3,"A","上下摆风",0,7),
    /**
     * B
     */
    LEFT_RIGHT_SWING("left_right_swing",3,"B","左右摆风",0,7),
    NOW_TIME_HOUR("now_time_hour",5,"B","当前小时",0,23),
    /**
     * C
     */
    OBLIGATE_1("obligate_1",1,"C","预留1 0.5度设置（预留",0,1),
    OBLIGATE_2("obligate_2",1,"C","预留2 发随身感码（预留）",0,1),
    NOW_TIME_MINUTE("now_time_minute",6,"C","当前分钟",0,59),
    /**
     * D
     */
    WIND_SPEED_1("wind_speed_1",3,"D","风速选择",0,7),
    TIME_HOUR("timer_hour",5,"D","定时时间小时",0,23),
    /**
     * E
     */
    TURBO_SILENCE("turbo_silence",2,"E","强力、静音（预留）",0,2),
    TIME_MINUTE("timer_minute",6,"E","定时分钟",0,59),
    /**
     * F
     */
    AIR_CON_FUNC("air_con_func",3,"F","模式",0,7),
    OBLIGATE_4("obligate_4",1,"F","预留4 清新（预留）",0,1),
    OBLIGATE_5("obligate_5",1,"F","预留5 随身感（预留）",0,1),
    SLEEP_MODE("sleep_mode",1,"F","睡眠",0,1),
    OBLIGATE_6("obligate_6",1,"F","预留6 未用",0,1),
    OBLIGATE_7("obligate_7",1,"F","预留7 人感功能",0,1),
    /**
     * G
     */
    OBLIGATE_8("obligate_8",2,"G","预留8 未定义",0,3),
    OBLIGATE_9("obligate_9",6,"G","预留9 室内温度检测（随身感用）（预留）",-10,53),
    /**
     * H
     */
    OBLIGATE_10("obligate_10",2,"H","预留10 未定义",0,3),
    OBLIGATE_11("obligate_11",6,"H","预留11 室内湿度设定（预留）",29,90),
    /**
     * I
     */
    OBLIGATE_12("obligate_12",2,"I","预留12 定时（预留）",0,3),
    ON_OFF("on_off",1,"I","开关机",0,1),
    ELECTRIC_HEATING("electric_heating",1,"I","电辅热",0,1),
    OBLIGATE_14("obligate_14",1,"I","预留14 ECO（预留）",0,1),
    OBLIGATE_15("obligate_15",1,"I","预留15 清洁（预留）",0,1),
    OBLIGATE_16("obligate_16",1,"I","预留16 健康（预留）",0,1),
    OBLIGATE_17("obligate_17",1,"I","预留17 空气清新（预留）",0,1),
    /**
     * J
     */
    OBLIGATE_18("obligate_18",1,"J","预留18 风速设定（预留4）",0,1),
    OBLIGATE_19("obligate_19",7,"J","预留19 无极调速比例",0,100),
    /**
     * K
     */
    OBLIGATE_20("obligate_20",2,"K","预留20",0,3),
    OBLIGATE_21("obligate_21",1,"K","预留21 电子锁（预留）",0,1),
    OBLIGATE_22("obligate_22",1,"K","预留22 显示板打开",0,1),
    OBLIGATE_23("obligate_23",1,"K","预留23 防霉（预留）",0,1),
    OBLIGATE_24("obligate_24",1,"K","预留24 自定义睡眠（预留）",0,1),
    CONTROL_MODE("control_mode",2,"K","控制优先级",0,3),

    /**
     * L
     */
    OBLIGATE_26("obligate_26",1,"M","预留26",0,1),
    OBLIGATE_27("obligate_27",7,"M","预留27",0,100),

    /**
     * M
     */
    OBLIGATE_28("obligate_28",4,"N","预留27",0,15),
    OBLIGATE_29("obligate_29",4,"N","预留27",0,9),
    ;

    /**
     * 数据点字段名称
     */
    private String name;

    /**
     * 在协议中二进制中所占bit位数
     */
    private int bitCount;
    /**
     * 中文描述
     */
    private String displayName;
    /**
     * 所在位置 A-M
     */
    private String position;
    /**
     * 最小值
     */
    private int min;
    /**
     * 最大值
     */
    private int max;

    BusinessDatapointControlEnum(String name, int bitCount, String position, String displayName, int min, int max) {
        this.name = name;
        this.bitCount = bitCount;
        this.position = position;
        this.displayName = displayName;
        this.min = min;
        this.max = max;
    }

    public String getPosition() {
        return position;
    }

    public String getName() {
        return name;
    }

    public int getBitCount() {
        return bitCount;
    }

    public int getMin() {
        return min;
    }

    public int getMax() {
        return max;
    }


    /**
     * key: 所在位置 A-M  value: A-M位置中所包含的对应数据点信息
     * @return 返回有序的映射map
     */
    public static Map<String,List<BusinessDatapointControlEnum>> getBusinessDatapointControlEnumMap(){
        Map<String,List<BusinessDatapointControlEnum>> datapointMap = new TreeMap<String,List<BusinessDatapointControlEnum>>();
        BusinessDatapointControlEnum[] values = BusinessDatapointControlEnum.values();
        for (int i = 0; i < values.length ; i++) {
            BusinessDatapointControlEnum value = values[i];
            List<BusinessDatapointControlEnum> datapointControlEnumList = datapointMap.get(value.getPosition());
            if (datapointControlEnumList == null){
                datapointControlEnumList = new ArrayList<BusinessDatapointControlEnum>();
                datapointMap.put(value.getPosition(),datapointControlEnumList);
            }
            datapointControlEnumList.add(value);
        }
        return datapointMap;
    }



}
